package com.ml.rocketmq.base.producer;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * 单向发送消息
 */
public class OnewayProducer {
	public static void main(String[] args) throws Exception{
        DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
        producer.setNamesrvAddr("localhost:9876");
        producer.start();

    	for (int i = 0; i < 100; i++) {
			byte[] body = ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET);
        	Message msg = new Message("TopicTest", "TagA", body);
			// 单向发送消息，没有任何返回结果
        	producer.sendOneway(msg);
    	}

    	producer.shutdown();
		System.out.println("producer shutdown");
	}
}